<template>
  <div class="container">
    <div class="title">
      <span>{{title}}</span>
      <span class="back" @click="back">
          <i class="iconfont icon-fanhui"></i> 返回
      </span>
    </div>
    <el-divider></el-divider>
    <el-form label-width="120px">
      <div class="wrap">
      <el-form-item label="商家状态">
        <el-radio v-model="status" label="0">不展示</el-radio>
        <el-radio v-model="status" label="1">展示</el-radio>
      </el-form-item>
        <el-form-item label="排序" prop="order_sort">
          <el-input
              size="medium"
              type="number"
              v-model="order_sort"
              placeholder="请填写排序(值越大越在前)"
          ></el-input>
        </el-form-item>
        <el-form-item label="选择用户" prop="order_sort">
          <el-select v-model="openid" clearable filterable placeholder="请选择用户">
            <el-option
                v-for="item in userAll"
                :key="item.openid"
                :label="item.nickname"
                :value="item.openid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="submit">
          <el-button type="primary" @click="updateData()">提 交</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import SjMsg from '@/models/sj-msg'
import User from '@/models/user'

export default {
  props: {
    SjMsgId: {
      type: Number,
    },
  },
  data() {
    return {
      title: '',
      status: '0',
      order_sort: '',
      openid: '',
      userAll: [],
    }
  },
  mounted() {
    this.getInfo()
    this.getUserAll()
  },
  methods: {
    async getInfo() {
      const info = await SjMsg.getDataInfo(this.SjMsgId)
      this.title = info.title
      this.status = info.status
      this.openid = info.openid
      this.order_sort = info.order_sort
    },
    async getUserAll() {
      const res = await User.getUserAll()
      this.userAll = res
    },
    back() {
      this.$emit('editCloseAdmin')
    },
    async updateData() {
      const self = this
      const info = {
        id: self.SjMsgId,
        title: self.title,
        order_sort: self.order_sort,
        openid: self.openid,
        status: self.status,
      }
      const res = await SjMsg.updateDataAdmin(info)
      if (res.error_code === 0) {
        this.$message.success(`${res.msg}`)
        this.back()
      }
    },
    change(val) {
      this.content = val
    },
  },
}
</script>

<style lang="scss" scoped>
.el-divider--horizontal {
  margin: 0;
}

.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
